home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / yase.arc / GROUP2.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-12-13  |  7.5 KB  |  225 lines

  1. ******************************************************************
  2. * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
  3. * - Note: This is a real, live, actual, registered copyright,
  4. *   and should be treated as such. This source code is from
  5. *   the book "68000 Assembly Language", Krantz and Stanley,
  6. *   Addison-Wesley Publishing Company, Reading, MA, 1986.
  7. *   Permission granted by the authors for non-commercial use
  8. *   in programs released to the public domain, as long as this
  9. *   copyright notice remains attached and visible.
  10. *
  11. *****************************************************************
  12. * GROUP 2 (Block) Commands
  13.  
  14.     xref    _getkey,ask,case,chk_blk,cnt_nl,default,dirty
  15.     xref    p_buf,p_cnt,prompt,putfile,query,readfile,seek
  16.     xref    writefile
  17.     xdef    group_2
  18.  
  19. #edit.h
  20. #cursor.h
  21. *****************************************************************
  22. * GROUP_2 - group 2 (block) commands
  23. group_2:
  24.     move.l    #k_cmd,a0    * load up prompt address
  25.     bsr    prompt        * output prompt
  26.     bsr    _getkey        * get switch key
  27.     and.w    #$001F,d0    * make u/l, l/c letters cntrl
  28.     move.l    #table2,a0    * load up case table address
  29.     bra    case        * returns to caller of group_2
  30. k_cmd:    dc.b    'Block Command: B C D P Q R S V W Y X',0
  31.     dc.w    0
  32. *****************************************************************
  33. * TABLE2 - switch table for group 2 commands
  34. table2:
  35.     dc.w    12        * number of case options
  36.     dc.w    $0B        * ^K mark block end
  37.     dc.l    mark_end
  38.     dc.w    $02        * ^B mark block start
  39.     dc.l    mark_start
  40.     dc.w    $03        * ^C copy block to cursor
  41.     dc.l    copy
  42.     dc.w    $04        * ^D end edit and save
  43.     dc.l    end_save
  44.     dc.w    $13        * ^S save and resume
  45.     dc.l    save
  46.     dc.w    $19        * ^Y cut block
  47.     dc.l    delete
  48.     dc.w    $10        * ^P Paste block
  49.     dc.l    paste
  50.     dc.w    $11        * ^Q abandon file
  51.     dc.l    abandon
  52.     dc.w    $17        * ^W write block
  53.     dc.l    write
  54.     dc.w    $12        * ^R read file
  55.     dc.l    readfile
  56.     dc.w    $16        * ^V move block
  57.     dc.l    mblock
  58.     dc.w    $18        * ^X end edit and save
  59.     dc.l    end_save
  60.     dc.l    default        * all other options
  61. *****************************************************************
  62. * MARK_END - marks the gap as the end of the block
  63. mark_end:
  64.     move.l    b_gap(a5),blk_end(a5)
  65.     rts
  66. *****************************************************************
  67. * MARK_START - marks the gap as the beginning of the block
  68. mark_start:
  69.     move.l    b_gap(a5),blk_st(a5)
  70.     rts
  71. *****************************************************************
  72. * MBLOCK - moves the marked block to the cursor
  73. mblock:
  74.     bsr    delete        * cut block
  75.     tst.w    ed_err(a5)    * check for errors
  76.     bne    sk0_mbl        * exit on error
  77.     bsr    paste        * insert block here
  78. sk0_mbl:
  79.     rts
  80. *****************************************************************
  81. * COPY - copies the marked block to the cursor
  82. copy:
  83.     bsr    chk_blk        * look for valid block
  84.     tst.w    ed_err(a5)    * look for error code
  85.     bne    sk0_cpy        * error jump out
  86.     move.l    b_gap(a5),-(a7)    * save    current cursor position
  87.     move.l    blk_end(a5),d0    * we want to have cursor at end
  88.     bsr    seek        * move to end of block
  89.     move.l    blk_st(a5),a0    * load source address
  90.     move.l    #p_buf,a1    * load destination address
  91.     move.l    blk_end(a5),d0    * calculate number of bytes
  92.     sub.l    a0,d0        * d0 is number of bytes
  93.     move.l    d0,d1        * save number of bytes
  94.     bra    sk1_cpy        * loop test before loop
  95. lp0_cpy:
  96.     move.b    (a0)+,(a1)+    * transfer bytes
  97. sk1_cpy:
  98.     dbra    d0,lp0_cpy    * loop test
  99.     move.l    (a7)+,d0    * get old cursor position
  100.     move.w    d1,p_cnt    * save byte count
  101.     bsr    seek        * go back to old cursor position
  102.     bsr    paste        * get stuff in
  103. sk0_cpy:
  104.     rts
  105. *****************************************************************
  106. * DELETE - cuts marked block and puts into paste buffer
  107. delete:
  108.     bsr    chk_blk        * look for valid block
  109.     tst.w    ed_err(a5)    * look for error code
  110.     bne    sk0_del        * error jump out
  111.     move.l    b_gap(a5),-(a7)    * save    current cursor position
  112.     move.l    blk_end(a5),d0    * we want to have cursor at end
  113.     bsr    seek        * move to end of block
  114.     move.l    blk_st(a5),a0    * load source address
  115.     move.l    #p_buf,a1    * load destination address
  116.     move.l    blk_end(a5),d0    * calculate number of bytes
  117.     sub.l    a0,d0        * d0 is number of bytes
  118.     move.l    d0,d1        * save number of bytes
  119.     bra    sk1_del        * loop test before loop
  120. lp0_del:
  121.     move.b    (a0)+,(a1)+    * transfer bytes
  122. sk1_del:
  123.     dbra    d0,lp0_del    * loop test
  124.     move.l    blk_st(a5),b_gap(a5)  ** erase block
  125.     move.l    (a7)+,d0    * get old cursor position
  126.     cmp.l    b_gap(a5),d0    * were we past cursor?
  127.     blt    sk2_del        * yes.
  128.     sub.l    d1,d0        * adjust for missing bytes
  129.     cmp.l    b_gap(a5),d0    * were we in gap?
  130.     bge    sk2_del        * no, we're ok still
  131.     move.l    b_gap(a5),d0    * fake it.
  132. sk2_del:
  133.     move.w    d1,p_cnt    * save byte count
  134.     bsr    seek        * go back to old cursor position
  135.     bsr    cnt_nl        * adjust line count
  136.     bsr    dirty        * mark file as modified
  137. sk0_del:
  138.     rts
  139. *****************************************************************
  140. * PASTE - pulls whatever's in paste buffer into cursor gap
  141. paste:
  142.     tst.w    p_cnt        * check if paste buffer used
  143.     beq    sk0_pas        * jump if empty
  144.     move.l    e_gap(a5),d0    * check for room.
  145.     sub.l    b_gap(a5),d0    * calculate gap size
  146.     cmp.w    p_cnt,d0    * test againt paste buffer
  147.     bcs    sk2_pas        * jump on error
  148.     bsr    dirty        * mark file as modified
  149.     move.l    b_gap(a5),a0    * get load address
  150.     move.l    #p_buf,a1    * get source address
  151.     move.w    p_cnt,d0    * get byte count
  152.     bra    sk3_pas        * loop test before move
  153. lp0_pas:
  154.     move.b    (a1)+,(a0)+    * transfer byte
  155. sk3_pas:
  156.     dbra    d0,lp0_pas    * loop for all bytes in p_buf
  157.     move.l    a0,b_gap(a5)    * save new gap start pointer
  158.     bsr    cnt_nl        * reset line count
  159.     bra    sk1_pas
  160. sk2_pas:
  161.     move.w    #10,ed_err(a5)    * load "block too large" code
  162.     bra    sk1_pas        * jump out
  163. sk0_pas:
  164.     move.w    #11,ed_err(a5)    * load "paste buffer empty" code
  165. sk1_pas:
  166.     rts
  167. *****************************************************************
  168. * WRITE - writes a marked block to disk
  169. write:    
  170.     bsr    chk_blk        * check for valid blocks
  171.     tst.w    ed_err(a5)    * look at return code
  172.     bne    sk0_wrt        * error jump
  173.     move.l    b_gap(a5),-(a7)    * save cursor position
  174.     move.l    blk_end(a5),d0    * setup for seek
  175.     bsr    seek        * seek end of block
  176.     move.l    blk_st(a5),a1    * setup for file write
  177.     move.l    blk_end(a5),d1    * compute number of bytes to write
  178.     sub.l    blk_st(a5),d1    * D1 is number of bytes in block
  179.     bsr    writefile    * go try to write file
  180.     move.l    (a7)+,d0    * now put cursor back
  181.     bsr    seek
  182. sk0_wrt:
  183.     rts
  184. *****************************************************************
  185. * SAVE - Saves file and resumes editing
  186. save:
  187.     move.l    b_gap(a5),-(a7)    * save current gap position
  188.     bsr    putfile        * save out the file
  189.     move.l    (a7)+,d0    * setup for seek
  190.     bsr    seek        * put cursor back
  191.     rts
  192. *****************************************************************
  193. * ABANDON - abondon file being edited
  194. abandon:
  195.     tst.w    modify(a5)    * check for changes
  196.     bne    sk0_abn        * confirm if modified
  197. lp0_abn:
  198.     clr.l    d0        * mark as don't resume editing
  199.     addq.l    #4,a7        * pop top return address
  200.     rts            * returns to 'edit's caller
  201. sk0_abn:
  202.     move.l    #confirm,a0    * confirm prompt
  203.     move.l    #query,a1    * general purpose response area
  204.     bsr    ask        * check with the human
  205.     and.b    #$5F,query    * make uppercase
  206.     cmp.b    #'Y',query    * test for 'Y' or 'y'
  207.     beq    lp0_abn        * human says ok, so dump it.
  208.     rts            * failed abandon exit
  209. confirm:
  210.     dc.b    'Abandon modified file? (Y/N) ',0
  211.     dc.w    0
  212. *****************************************************************
  213. end_save:
  214.     bsr    putfile        * write the file to disk
  215.     tst.w    d0        * check return code
  216.     bne    sk0_ener    * jump if error
  217.     clr.l    d0        * mark as don't resume editing
  218.     addq.l    #4,a7        * pop top return address
  219.     rts            * returns to caller of EDIT
  220. sk0_ener:
  221.     rts            * and back to edit main loop
  222.  
  223.     end
  224.